package com.zombie.logic.item;

import org.w3c.dom.Node;

import com.zombie.logic.enums.ItemType;

public class Explosive extends Item {

	public float damage;
	public int radius;
	public float velocity;
	public int timer;
	public String condition;
	public boolean blowOnContact;
	public String explodeSound = "explode_0";
	public String explodeParticle = "explode_0";
	public float detectorRadius;	
	
	public Explosive(){
		type = ItemType.EXPLOSION;
	}
	
	public static Item loadExplosive(Node node) {
		Explosive heal = new Explosive();
		heal.id = Integer.parseInt(node.getAttributes().getNamedItem("id").getNodeValue());
		heal.name = node.getAttributes().getNamedItem("name").getNodeValue();
		for(int i = 0; i < node.getChildNodes().getLength();i++ ){
			Node n = node.getChildNodes().item(i);
			if (n.getNodeName().equalsIgnoreCase("param")) {
				String name =  n.getAttributes().getNamedItem("name").getNodeValue();
				if (name.equalsIgnoreCase("radius"))
					heal.radius = Integer.parseInt(n.getTextContent());
				else if (name.equalsIgnoreCase("damage"))
					heal.damage = Integer.parseInt(n.getTextContent());
				else if (name.equalsIgnoreCase("velocity"))
					heal.velocity = Float.parseFloat(n.getTextContent());
				else if (name.equalsIgnoreCase("timer"))
					heal.timer = Integer.parseInt(n.getTextContent());
				else if (name.equalsIgnoreCase("condition"))
					heal.condition = n.getTextContent();
				else if (name.equalsIgnoreCase("blowoncontact"))
					heal.blowOnContact = Boolean.parseBoolean(n.getTextContent());
				else if (name.equalsIgnoreCase("explodesound"))
					heal.explodeSound = n.getTextContent();	
				else if (name.equalsIgnoreCase("particle_explode"))
					heal.explodeParticle = n.getTextContent();
				else if (name.equalsIgnoreCase("detectorRadius"))
					heal.detectorRadius = Float.parseFloat(n.getTextContent());	
			}
		}
		items.put(heal.id, heal);
		return heal;
	}

}
